/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { Component } from 'react';
import { Tabs } from 'antd';
import Lib from './Lib';
import AiInput from './AiInput';
import CustomInput from './CustomInput';
import FileImport from './FileImport';

const { TabPane } = Tabs;
class Editor extends Component {
    static defaultProps = {
        onChange: () => {
        },
    };

    constructor(props) {
        super(props);
        this.state = {activeKey: props.type === 'send' ? 'lib' : 'ai'};
    }

    onSwitchTab = activeKey => {
        this.setState({activeKey});
    };

    onChange = this.props.onChange;

    render() {
        const { activeKey } = this.state;
        const { type } = this.props;
        return (
            <>
            {
                type === 'receive' ? <Tabs activeKey={activeKey} onChange={this.onSwitchTab} className="kb-tab-arrow"
                                           style={{maxWidth:activeKey=='input'?'100%':'760px'}}>
                    <TabPane tab="传统录入" key="input">
                        <CustomInput
                            type={type}
                            onSave={this.onChange}
                            okText={type === 'send' ? '保存' : '添加'}
                            layout="inline"
                        />
                    </TabPane>
                    <TabPane tab="智能录入" key="ai">
                        <AiInput type={type} onParse={this.onChange}/>
                    </TabPane>
                    <TabPane tab="地址薄" key="lib">
                        <Lib type={type} onSelect={this.onChange}/>
                    </TabPane>
                    <TabPane tab="文档导入" key="import">
                        <FileImport type={type} onImport={this.onChange}/>
                    </TabPane>
                </Tabs> : <Tabs activeKey={activeKey} onChange={this.onSwitchTab} className="kb-tab-arrow"
                                style={{maxWidth:activeKey=='input'?'100%':'660px'}}>
                    <TabPane tab="地址薄" key="lib">
                        <Lib type={type} onSelect={this.onChange}/>
                    </TabPane>
                    <TabPane tab="智能录入" key="ai">
                        <AiInput type={type} onParse={this.onChange}/>
                    </TabPane>
                    <TabPane tab="传统录入" key="input">
                        <CustomInput
                            type={type}
                            onSave={this.onChange}
                            okText={type === 'send' ? '保存' : '添加'}
                        />
                    </TabPane>
                </Tabs>
            }
            </>

        );
    }
}

export default Editor;
